<template>
	<view>
		
	
		<view class="content">
			<u-input class="input-view" v-model="value" type="text" @click="show=true" disabled placeholder="请选择生日"   />
		</view>
		
		<button class="bottom-btn" @click="saveAction" >保存</button>
		
		
		<u-picker mode="time" v-model="show" :params="params" default-time="2020-03-04" @confirm="confirm" ></u-picker>
		
	</view>
</template>

<script>

export default {
	data() {
		return {
			value: '',
			value2: '',
			sexName: '',
			showClearIcon: true,
			show: false   ,//生日选择
			params: {
				year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false
			},
			defaultTime: '',	//当前时间
		};
	},
	computed: {
		
	},
	onLoad(options) {
		
		if(options.data != undefined){
			this.value = this.value2 = options.data;
			if(this.value){
				this.defaultTime = this.value
			}else{
				const now = new Date()
				const year = now.getFullYear()
				const month = now.getMonth()
				const day = now.getDate()
				this.defaultTime = `${year}-${month}-${day}`
				console.log('获取当前日期',now.toLocaleDateString())
			}
		}
	},
	onShow() {
		
	},
	watch:{
	
	},
	methods: {
		
		saveAction(){  //保存按钮
			if (this.value == '') {
				uni.showToast({
					title: '生日不能为空',
					icon: "none"
				})
			}else if(this.value == this.value2){
				uni.navigateBack();
			}else{
				this.getName();
			}
		},
		
		clearInput(event) {
			
		},
		clearIcon() {
			this.value = '';
			this.showClearIcon = false;
		},
		confirm(e){
			console.log('e',e)
			this.value = `${e.year}-${e.month}-${e.day}`
		},
		
		getName(){
			
			this.$https.Mine.changeBirthday(this.value).then(res=>{
				
				uni.navigateBack();
			})
		}
	}
};
</script>

<style lang="scss">
page {
	background: rgb(250,250,250);
}

.content{
	
	display: flex;
	align-items: center;
	margin-top: 16upx;
	width: 100%;
	height: 100upx;
	
	background: #FFFFFF;
	
}
	
.input-view {
	
	margin: 0 20rpx;

	width: 100%;
	background: #fff;
	// text-indent: 40upx;
}

.uni-icon-clear {
	position: absolute;
	top: 35upx;
	right: 30upx;
	
}

.bottom-btn{
	
	margin: 30rpx;
	
	border-radius: 8rpx;
	font-size: $uni-font-size-base;
	color: #FFFFFF;
	background-color: $uni-color-error;
}
button::after{
	border: none;
}
</style>
